{extend name='index@template/base'}{/extend}
{block name='style'}{/block}
{block name='script'}{/block}
{block name='content'}
<div class="row">
    <div class="col-xs-12">
        <div class="box box-primary">
            <div class="box-body">
                <div id="toolbar">
                    <!--<div class="btn-group pull-left mr10">-->
                        <!--<a class="btn btn-primary" id="add_btn"><i class="fa fa-plus"></i> 新增</a>-->
                    <!--</div>-->
                </div>
                <table id="table"
                       data-toggle="table"
                       data-side-pagination="server"
                       data-pagination="true"
                       data-url="{:url('WechatBaseReply/index_data')}"
                >
                    <thead>
                    <tr>
                        <th data-field="title">规则名称</th>
                        <!--<th data-field="type" >消息类型</th>-->
                        <!--<th data-field="match_type">匹配方式</th>-->
                        <!--<th data-field="pattern" data-formatter="formatPattern">匹配模板</th>-->
                        <th data-field="content">回复内容</th>
                        <th data-field="status"  data-class="sm-hide" data-formatter="formatStatus">是否启用</th>
                        <th data-field="is_welcome"  data-class="sm-hide" data-formatter="formatWelcome">是否设为欢迎信息</th>
                        <!--<th data-field="create_time"  data-formatter="formatDate">记录时间</th>-->
                        <th data-field="operate" data-formatter="formatOperate" data-events="operateEvents" >操作</th>
                    </tr>
                    </thead>
                </table>
            </div><!-- /.box-body -->
        </div><!-- /.box -->
    </div><!-- /.col -->
</div><!-- /.row -->

{/block}
{block name='script_extra'}
<script>
    var add_data_url="{:url('BaseReply/add_data')}";
</script>
<script>
    // <editor-fold defaultstate="collapsed" desc="匹配模板">
    var strs=[]; //定义一数组
    function formatPattern(value) {
        var html="<div>";
        strs=value.split("|"); //字符分割
        for (var i=0;i<strs.length ;i++ )
        {
            html+='<button style="margin-right: 5px" class="btn btn-xs row_edit" href="javascript:void(0)">'+strs[i]+'</button>'
        }
        html+="</div>";
        return html;
    }
    // </editor-fold>
    // <editor-fold defaultstate="collapsed" desc="type">
    function formatType(value) {
        if (parseInt(value) == 1) {
            return '<button class="btn btn-success btn-xs row_edit" href="javascript:void(0)"></button>';
        }
    }
    // </editor-fold>
    // <editor-fold defaultstate="collapsed" desc="定义设为欢迎信息">
    function formatWelcome(value) {
        if (parseInt(value) == 1) {
            return '<i class="fa fa-check-circle text-green" title="设为欢迎信息">设为欢迎信息</i>';
        }
    }
    // </editor-fold>
    // <editor-fold defaultstate="collapsed" desc="定义状态">
    function formatStatus(value) {
        if (parseInt(value) == 1) {
            return '<i class="fa fa-check-circle text-green" title="启用">启用</i>';
        }
        if (parseInt(value) == 0) {
            return '<i class="fa fa-minus-circle text-yellow" title="禁用">禁用</i>';
        }
    }
    // </editor-fold>
    // <editor-fold defaultstate="collapsed" desc="定义时间">
    function formatDate(value) {
        var date = new Date(parseInt(value) * 1000);
        Y = date.getFullYear() + '-';
        M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
        D = (date.getDate() + 1 < 10 ? '0' + (date.getDate()) : date.getDate()) + ' ';
        h = (date.getHours() + 1 < 10 ? '0' + (date.getHours()) : date.getHours()) + ':';
        m = (date.getMinutes() + 1 < 10 ? '0' + (date.getMinutes()) : date.getMinutes()) + ':';
        s = (date.getSeconds() + 1 < 10 ? '0' + (date.getSeconds()) : date.getSeconds());
        return Y + M + D + h + m + s;
    }
    // </editor-fold>
    // <editor-fold defaultstate="collapsed" desc="添加">
    $('#add_btn').on('click',function(){
        layer_open('添加自定义菜单',"{:url('WechatMenu/add')}")
    })
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="操作">
    function formatOperate(value, row, index) {
        return [
            '<button class="btn btn-warning btn-sm row_edit" href="javascript:void(0)">',
            '编辑',
            '</button>&nbsp;'
        ].join('');
    }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="操作函数">
    window.operateEvents = {
        'click .row_edit': function (e, value, row, index) {
            layer_open('编辑',urlFormat("{:url('wechat/WechatBaseReply/edit_data')}")+"/id/"+row.id);
        }
    };

    // </editor-fold>
</script>
{/block}